﻿<UserControl x:Class="Sentinel.FileMonitor.FileMonitorProviderPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:conv="clr-namespace:WpfExtras.Converters;assembly=WpfExtras"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300">
    <UserControl.Resources>
        <conv:VisibilityToHiddenConverter x:Key="visToHidden" />

        <Style x:Key="textBoxInError"
               TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError"
                         Value="true">
                    <Setter Property="ToolTip"
                            Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors).CurrentItem.ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid Grid.IsSharedSizeScope="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"
                              SharedSizeGroup="label" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto"
                              SharedSizeGroup="extra" />
        </Grid.ColumnDefinitions>

        <GroupBox Margin="3" Header="File to monitor" Grid.ColumnSpan="3">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="label" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition SharedSizeGroup="extra" />
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0"
                           Grid.Row="0"
                           Margin="3"
                           Text="File Name : "
                           VerticalAlignment="Center" />
                <TextBox Grid.Column="1"
                         Grid.Row="0"
                         Margin="3"
                         Style="{StaticResource textBoxInError}"
                         Text="{Binding FileName, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}"
                         VerticalAlignment="Center" />
                <Button Grid.Row="0"
                        Grid.Column="2"
                        Content="Browse..."
                        Command="{Binding Browse}"
                        VerticalAlignment="Center"
                        Width="75"
                        Height="23"
                        Margin="3" />

            </Grid>
        </GroupBox>

        <GroupBox Header="Options"
                  Margin="3"
                  Grid.Row="1"
                  Grid.Column="0"
                  Grid.ColumnSpan="3">
            <Grid >
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="label" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition SharedSizeGroup="extra" />
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0"
                           Text="Refresh Period : "
                           VerticalAlignment="Center" />
                <Slider Value="{Binding Refresh, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                        Minimum="{Binding MinRefresh}"
                        Maximum="{Binding MaxRefresh}"
                        Grid.Column="1" 
                        Margin="3"/>
                <StackPanel Orientation="Horizontal" Grid.Column="2" HorizontalAlignment="Center">
                    <TextBlock Text="{Binding Refresh, StringFormat=0}"
                               Margin="10,0,10,0"
                               VerticalAlignment="Center" />
                    <TextBlock Text="ms"
                               VerticalAlignment="Center" />
                </StackPanel>
                <CheckBox Margin="3"
                          Grid.Row="1"
                          Grid.Column="0"
                          Grid.ColumnSpan="3"
                          IsChecked="{Binding LoadExisting, Mode=TwoWay}"
                          Content="Load existing content from log file."
                          ToolTip="If there are existing log entries in the file, should they be loaded into the logger?" />
            </Grid>
        </GroupBox>

        <StackPanel Grid.Row="2"
                    Grid.ColumnSpan="3"
                    HorizontalAlignment="Center"
                    Margin="10"
                    Visibility="{Binding WarnFileNotFound, Converter={StaticResource visToHidden}, UpdateSourceTrigger=PropertyChanged}">
            <TextBlock TextWrapping="WrapWithOverflow"
                       Margin="3"
                       Foreground="Red"
                       FontWeight="Bold"
                       Text="Warning, the file specified does not yet exist!" />
            <TextBlock Margin="3"
                       TextWrapping="WrapWithOverflow"
                       Foreground="Red"
                       FontWeight="Bold"
                       Text="You may continue if the log file will be created later."
                       Loaded="OnLoaded" />
        </StackPanel>
    </Grid>
</UserControl>